from init.celery_init import init_celery
from init.app_init import create_app
from init.celery import celery
from datetime import timedelta

app = create_app()
init_celery(app)

celery.conf.timezone = "Asia/Shanghai"
# 是否使用UTC
celery.conf.enable_utc = False
# 自动发现 tasks 包里的所有模块
celery.autodiscover_tasks(['celery_related.common_tasks',
                           "celery_related.delay_tasks",
                           "celery_related.sche_tasks"],
                          force=True)

# 每隔5s爬一次百度
celery.conf.beat_schedule = {
    "crwal_info": {
        "task": "celery_related.sche_tasks.tasks.crwal_info",
        "schedule": timedelta(seconds=5),
        "args": (),
    }
}

# celery -A celery_worker.celery worker -l info
# celery -A celery_worker.celery beat -l info

# if __name__ == '__main__':
#     celery.start(["worker", '--beat', '--loglevel=info'])
